<template>
  <div>
    <div class="page-body" :class="{ 'page-body-select': tabsState.selectTabId == dataOption.id }" @click="onClickItem">
      <div class="page-icon">
        <img :src="dataOption.icon" />
      </div>
      <div class="page-content">{{ dataOption.title }}</div>
      <div class="page-close" v-if="dataOption.name !== 'Home'" @click.stop="onClickClose"></div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from "vue";
import { TabItemClass } from "@/model/AppModel";
import { tabsState, tabsAction } from "@/store/tabs";

export default defineComponent({
  name: "AppTabItem",
})
</script>

<script setup lang="ts">
import { withDefaults } from "vue";

let props = withDefaults(defineProps<{
  dataOption: TabItemClass;
}>(), {
})

/**
 * 点击按钮
 */
function onClickItem() {
  tabsAction.selectTab(props.dataOption.id)
}

/**
 * 点击关闭当前页面
 */
function onClickClose() {
  tabsAction.removeTab(props.dataOption.id)
}

</script>

<style lang="less" scoped>
@import url("../../config.less");

.page-body {
  height: 100%;
  border-radius: var(--app-border-radius);
  display: flex;
  // justify-content: center;
  justify-content: space-between;
  align-items: center;
  padding: 0 5px;
  min-width: 150px;
  display: flex;
  user-select: none;
  padding: 0 10px;
  // border-left: 1px solid rgba(0, 0, 0, 0);
  cursor: pointer;
  color: rgba(0, 0, 0, 0.5);
  position: relative;

  &:hover {
    background-color: rgba(0, 0, 0, 0.04);
  }

  &:hover>.page-close {
    opacity: 1;
  }

  // &::before {
  //   content: "";
  //   transition: 0.2s;
  //   width: 40px;
  //   height: 3px;
  //   border-radius: 5px;
  //   background-color: rgba(0, 0, 0, 0);
  //   position: absolute;
  //   left: 50%;
  //   margin-left: -20px;
  //   bottom: 0;
  // }

  // &::after {
  //   content: "";
  //   width: 0.5px;
  //   height: 16px;
  //   border-radius: 5px;
  //   background-color: rgba(0, 0, 0, 0.2);
  //   position: absolute;
  //   right: 0;
  // }
}

.page-icon {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  flex-shrink: 0;

  >img {
    width: 100%;
    height: 100%;
  }
}

.page-content {
  margin: 0 5px;
  flex-grow: 1;
}

.page-close {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  position: relative;

  .page-close-l {
    width: 50%;
    height: 1px;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 5px;
    position: absolute;
  }

  &::after {
    content: "";
    .page-close-l;
    transform: rotate(45deg);
  }

  &::before {
    content: "";
    .page-close-l;
    transform: rotate(135deg);
  }

  &:hover {
    background-color: rgba(0, 0, 0, 0.1);
  }
}

// 被选中
.page-body-select {
  opacity: 1;
  background-color: white;
  // border: 1px solid var(--primaryColor);
  position: relative;
  font-weight: bold;
  color: black;
  // border:1px solid rgba(0, 0, 0, 0.1);
  // &::after {
  //   background-color: white;
  // }
  // filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.1));

  .page-close {
    opacity: 1;
  }

  &:hover {
    background-color: rgba(255, 255, 255, 0.8);
  }
}
</style>
